package com.yootk;

import java.util.concurrent.atomic.AtomicReference;

class Book1 {
    private String title;    // 图书名称
    private double price;    // 图书价格

    public Book1() {}    // 无参构造

    public Book1(String title, double price) {    // 双参构造
        this.title = title;    // 属性赋值
        this.price = price;    // 属性赋值
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "【图书】名称 = " + this.title + "，价格 = " + this.price;
    }
}

public class YootkDemo4 {
    public static void main(String[] args) throws Exception {
        Book book = new Book("Java就业编程实战", 69.8);    // 实例化Book类对象
        AtomicReference<Book> ref = new AtomicReference<Book>(book);    // 原子引用
        ref.compareAndSet(book, new Book("Spring就业编程实战", 67.8));    // CAS操作
        System.out.println(ref.get());    // 获取引用数据
    }
}